<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row style="margin-bottom:10px">
            <el-col><span style="font-size:14px;;color:#2A8BD8;"><i
                  class="el-icon-menu"></i>甲方信息：</span></el-col>
      </el-row>
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="甲方名称" prop="partyName"
                 :rules="[{required: true, message:'甲方名称不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.partyName" placeholder="请填写甲方名称"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="甲方负责人" prop="partyPerson"
                :rules="[{required: true, message:'甲方负责人不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.partyPerson" placeholder="请填写甲方负责人"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="甲方电话" prop="partyPhone"
               :rules="[{required: true, message:'甲方电话不能为空', trigger:'blur',pattern: /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/,}]">
              <el-input v-model="inputForm.partyPhone" placeholder="请填写甲方电话"></el-input>
           </el-form-item>
        </el-col>
      </el-row>
      <el-row style="margin-bottom:10px">
            <el-col><span style="font-size:14px;;color:#2A8BD8;"><i
                  class="el-icon-menu"></i>乙方信息：</span></el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
            <el-form-item label="乙方名称" prop="secondName"
               :rules="[{required: true, message:'乙方名称不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.secondName" placeholder="请填写乙方名称"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="乙方负责人" prop="secondPerson"
               :rules="[{required: true, message:'乙方负责人不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.secondPerson" placeholder="请填写乙方负责人"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="乙方电话" prop="secondPhone"
              :rules="[{required: true, message:'乙方电话不能为空', trigger:'blur',pattern: /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/,}]">
              <el-input v-model="inputForm.secondPhone" placeholder="请填写乙方电话"></el-input>
           </el-form-item>
        </el-col>
      </el-row>
      <el-row style="margin-bottom:10px">
            <el-col><span style="font-size:14px;;color:#2A8BD8;"><i
                  class="el-icon-menu"></i>代理机构信息：</span></el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
            <el-form-item label="代理机构名称" prop="mechanismName"
               :rules="[{required: true, message:'代理机构名称不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.mechanismName" placeholder="请填写代理机构名称"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="代理机构负责人" prop="mechanismPerson"
               :rules="[{required: true, message:'代理机构负责人不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.mechanismPerson" placeholder="请填写代理机构负责人"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="代理机构电话" prop="mechanismPhone"
               :rules="[{required: true, message:'代理机构电话不能为空', trigger:'blur',pattern: /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/,}]">
              <el-input v-model="inputForm.mechanismPhone" placeholder="请填写代理机构电话"></el-input>
           </el-form-item>
        </el-col>
        </el-row>
      <el-row style="margin-bottom:10px">
            <el-col><span style="font-size:14px;;color:#2A8BD8;"><i
                  class="el-icon-menu"></i>投标信息：</span></el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
            <el-form-item label="标数购买日期" prop="markingDate"
                :rules="[{required: true, message:'标数购买日期不能为空', trigger:['blur','change']}]">
              <!-- <el-input v-model="inputForm.markingDate" placeholder="请填写标数购买日期"     ></el-input> -->
              <el-date-picker
                  v-model="inputForm.markingDate"
                  type="date"
                  size="small" style="width:100%"
                  value-format="yyyy-MM-dd"
                  placeholder="请填写标数购买日期">
                </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开标日期" prop="bidOpeningDate"
               :rules="[{required: true, message:'开标日期不能为空', trigger:['blur','change']}]">
              <!-- <el-input v-model="inputForm.bidOpeningDate" placeholder="请填写开标日期"     ></el-input> -->
              <el-date-picker
                  v-model="inputForm.bidOpeningDate"
                  type="date"
                  size="small" style="width:100%"
                  value-format="yyyy-MM-dd"
                  placeholder="请填写开标日期">
                </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开标地点" prop="bidOpeningLocation"
               :rules="[{required: true, message:'开标地点不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.bidOpeningLocation" placeholder="请填写开标地点"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目编号" prop="itemNumber"
               :rules="[{required: true, message:'项目编号不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.itemNumber" placeholder="请填写项目编号"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目名称" prop="itemName"
               :rules="[{required: true, message:'项目名称不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.itemName" placeholder="请填写项目名称"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标负责人" prop="tenderPerson"
               :rules="[{required: true, message:'投标负责人不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.tenderPerson" placeholder="请填写投标负责人"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标负责人电话" prop="tenderPhone"
               :rules="[{required: true, message:'投标负责人电话不能为空', trigger:'blur',pattern: /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/,}]">
              <el-input v-model="inputForm.tenderPhone" placeholder="请填写投标负责人电话"></el-input>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="中标状态" prop="winningStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.winningStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('winning_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="投标保证金" prop="bidBond"
               :rules="[{required: true, message:'投标保证金不能为空', trigger:'blur'}]">
              <el-input v-model="inputForm.bidBond" placeholder="请填写投标保证金" @input="bidBondBig"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标保证金大写" prop="upBidBond">
              <el-input v-model="inputForm.upBidBond" disabled></el-input>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="保证金支付状态" prop="marginPaymentStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.marginPaymentStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('margin_payment_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col> -->
        <!-- <el-col :span="12">
            <el-form-item label="投标服务费大写" prop="upBiddingService"
                :rules="[
                 ]">
              <el-input v-model="inputForm.upBiddingService" placeholder="请填写投标服务费大写"     ></el-input>
           </el-form-item>
        </el-col> -->
        <!-- <el-col :span="12">
            <el-form-item label=" 服务费支付状态" prop="serviceFeeStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.serviceFeeStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('margin_payment_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col> -->
        <!-- <el-col :span="12">
            <el-form-item label="投标服务费" prop="biddingService"
                :rules="[
                 ]">
              <el-input v-model="inputForm.biddingService" placeholder="请填写投标服务费"     ></el-input>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          partyName: '',
          partyPerson: '',
          partyPhone: '',
          secondName: '',
          secondPhone: '',
          secondPerson: '',
          mechanismName: '',
          mechanismPerson: '',
          mechanismPhone: '',
          markingDate: '',
          bidOpeningDate: '',
          bidOpeningLocation: '',
          itemNumber: '',
          itemName: '',
          tenderPerson: '',
          tenderPhone: '',
          winningStatus: '',
          bidBond: '',
          upBidBond: '',
          marginPaymentStatus: '',
          upBiddingService: '',
          serviceFeeStatus: '',
          biddingService: '',
          remarks: '',
          company:this.$store.state.user.companyId,
        }
      }
    },
    components: {
    },
    methods: {
      //投标大写
      bidBondBig(){
         var money=this.inputForm.bidBond;
        var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
        //基本单位
        var cnIntRadice = new Array('', '拾', '佰', '仟');
        //对应整数部分扩展单位
        var cnIntUnits = new Array('', '万', '亿', '兆');
        //对应小数部分单位
        var cnDecUnits = new Array('角', '分', '毫', '厘');
        //整数金额时后面跟的字符
        var cnInteger = '整';
        //整型完以后的单位
        var cnIntLast = '元';
        //最大处理的数字
        var maxNum = 999999999999999.9999;
        //金额整数部分
        var integerNum;
        //金额小数部分
        var decimalNum;
        //输出的中文金额字符串
        var chineseStr = '';
        //分离金额后用的数组，预定义
        var parts;
        if (money == '') { this.inputForm.upBidBond=chineseStr }
        money = parseFloat(money);
        if (money >= maxNum) {
          //超出最大处理数字
          return '';
        }
        if (money == 0) {
          chineseStr = cnNums[0] + cnIntLast + cnInteger;
        }
        //转换为字符串
        money = money.toString();
        if (money.indexOf('.') == -1) {
          integerNum = money;
          decimalNum = '';
        } else {
          parts = money.split('.');
          integerNum = parts[0];
          decimalNum = parts[1].substr(0, 4);
        }
        //获取整型部分转换
        if (parseInt(integerNum, 10) > 0) {
          var zeroCount = 0;
          var IntLen = integerNum.length;
          for (var i = 0; i < IntLen; i++) {
            var n = integerNum.substr(i, 1);
            var p = IntLen - i - 1;
            var q = p / 4;
            var m = p % 4;
            if (n == '0') {
              zeroCount++;
            } else {
              if (zeroCount > 0) {
                chineseStr += cnNums[0];
              }
              //归零
              zeroCount = 0;
              chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
            }
            if (m == 0 && zeroCount < 4) {
              chineseStr += cnIntUnits[q];
            }
          }
          chineseStr += cnIntLast;
        }
        //小数部分
        if (decimalNum != '') {
          var decLen = decimalNum.length;
          for (var i = 0; i < decLen; i++) {
            var n = decimalNum.substr(i, 1);
            if (n != '0') {
              chineseStr += cnNums[Number(n)] + cnDecUnits[i];
            }
          }
        }
        if (chineseStr == '') {
          chineseStr += cnNums[0] + cnIntLast + cnInteger;
        } else if (decimalNum == '' && money != 0) {
          chineseStr += cnInteger;
        }
        this.inputForm.upBidBond=chineseStr         
      },
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建招投标管理`
        } else if (method === 'edit') {
          this.title = '修改招投标管理'
        } else if (method === 'view') {
          this.title = '查看招投标管理'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/biddingmanagement/biddingManagement/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.biddingManagement)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/biddingmanagement/biddingManagement/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>